package com.aaa.wash.controller;

import com.aaa.common.entity.Car;
import com.aaa.common.util.BaseUtil;
import com.aaa.common.util.Result;
import com.aaa.common.vo.Page;
import com.aaa.wash.service.CarService;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Car)表控制层
 *
 * @author makejava
 * @since 2025-10-09 10:29:15
 */
@RestController
@RequestMapping("carFront")
@Log4j2
public class CarController {
    /**
     * 服务对象
     */
    @Resource
    private CarService carService;

    @GetMapping("selectByUserIdAndStoreId")
    public Result selectByUserIdAndStoreId(Integer storeId) {
        return BaseUtil.success(this.carService.selectByUserIdAndStoreId(storeId));
    }

    @DeleteMapping("deleteByCarNo")
    public Result deleteByCarNo(String carNo) {
        return BaseUtil.success(this.carService.deleteByCarNo(carNo));
    }

    @GetMapping("queryStoreNumber")
    public Result queryStoreNumber() {
        return BaseUtil.success(this.carService.queryStoreNumber());
    }

    /**
     * 分页查询
     *
     * @param page 分页对象
     * @return 查询结果
     */
    @PostMapping("queryByPage")
    public Result queryByPage(@RequestBody Page<Car> page) {
        return BaseUtil.success(this.carService.queryByPage(page));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("queryById")
    public Result queryById(Integer id) {
        return BaseUtil.success(this.carService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param car 实体
     * @return 新增结果
     */
    @PostMapping("add")
    public Result add(@RequestBody Car car) {
        return BaseUtil.success(this.carService.insert(car));
    }

    /**
     * 编辑数据
     *
     * @param car 实体
     * @return 编辑结果
     */
    @PostMapping("edit")
    public Result edit(@RequestBody Car car) {
        return BaseUtil.success(this.carService.update(car));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("deleteById")
    public Result deleteById(Integer id) {
        return BaseUtil.success(this.carService.deleteById(id));
    }

}

